/**
 * 
 * @Project le cOeur - Data Virtualization
 * @Date 08.12.2012
 * @Author Aebi Pascal, Kocher Marc
 * @School BFH-TI Biel, Bachelor Thesis
 *
 */

package main.framework.security;

import java.net.URI;

import main.framework.exception.SecurityAccessException;
import main.framework.exception.SecurityPermissionException;
import main.framework.http.Method;

/**
 * This class extends the java security manager and provides some specific new functions.
 */
public class ExtendedSecurityManager extends SecurityManager {

	private AccessList accessList;

	/**
	 * Creates an extended security manager.
	 */
	public ExtendedSecurityManager() {
		super();
	}
	
	/**
	 * Sets a server access list.
	 * The list could either be a white or a black list.
	 * Only one of the two possibilities can be set.
	 * 
	 * @param accessList The access list.
	 */
	public void setServerAccess(AccessList accessList) {
		this.accessList = accessList;
	}
	
	/**
	 * Checks if the given host is permitted to access the server.
	 * The given host must be either an IP address or a domain name.
	 * 
	 * @param host The host.
	 */
	public synchronized void checkServerAccess(String host) throws SecurityAccessException {
		if(this.accessList != null){
			this.accessList.checkAccessList(host);
		}
	}
	
	/**
	 * Sets the permissions from the resource URIs.
	 * Not yet implemented.
	 */
	public void setURIPermissions() {
		
	}
	
	/**
	 * Checks if the given HTTP method is allowed to execute for the requested URI.
	 * Not yet implemented.
	 * 
	 * @param requestedURI
	 * @param method
	 */
	public synchronized void checkURIPersmission(URI requestedURI, Method method) throws SecurityPermissionException {
		
	}
	
	/**
	 * Checks if the given host is trying to denial the service by sending a flood of requests.
	 * Not yet implemented.
	 * 
	 * @param host
	 * @param port
	 */
	public synchronized void checkDOSAttack(String host, int port) {
		
	}

}
